<?php
	session_start();
	require_once('common/config.php');
	require_once('../_helper/paging.php');
	require_once('../_helper/helper.php');
	require_once('../_model/order_model.php');
	
	$pageCMS = PAGE_CMS_ORDER;
	$keyword = '';
	
	if(!isset($_SESSION['logon']))
	{
		header("Location: /wks/login.php?url=order");
		exit();
	}
	if($_SESSION['user'] == USER_PRODUCT)
	{
		header("Location: /wks");
		exit();
	}
	
	if (!isset($_GET['action']))
		$_GET['action'] = "list";
		
	if (isset($_GET['id'])){
		$order_id = $_GET['id'];
		}
	if (isset($_GET['keyword'])){
		$keyword = $_GET['keyword'];
	}

	
	$action = $_GET['action'];
	
	if($action == 'list' || $action =='search')
	{
		if(isset($_GET['page']))
			$curPage = $_GET['page'];
		else
		{
			$curPage = 0;
			unset($_SESSION['numOrder']);
		}
			
		
		/*var_dump($type_arr);die();*/
		if( !isset($_SESSION['numOrder']))
		{
			$numOrder = GetNumOrderSearch($keyword);
			$_SESSION['numOrder'] = $numOrder;
		}
		else
			$numOrder = $_SESSION['numOrder'];
			
		$param = "action=search&keyword={$keyword}";	
		
		$order_arr = GetOrderSearch($curPage, PAGING_NUM_ROW,$keyword);
		
				
		//Xu ly
		require_once('template/order/order_list.php');
		exit();
	}
	
	if($action == 'edit')
	{
		// if (!isset($order_id))
			// header("Location: /wks/order.php");		
			
		// if(!isset($_POST['submit'])){
			// $order_value = GetOrderById($order_id);
			// $brand_arr = GetBrandAll();
			// $type_arr = GetTypeList();
			// $cat_arr = GetCatList();
			// require_once('template/order/order_edit.php');
			// exit();
		// }
		// else{
			// if($_POST['order_name'] != '' && $_POST['brand_id'] != '' && $_POST['type_id']!='')
			// {
				
								
				// $order   = array("\r\n", "\n", "\r", "\t", "  ");
				// $_POST['order_des_short'] = str_replace($order,'',$_POST['order_des_short']);
				// $_POST['order_des_full'] = str_replace($order,'',$_POST['order_des_full']);
				
				// EditOrder($order_id, $_POST);
				// header("Location: /wks/order.php?action=list");
			// }
		// }
		// exit();
	}
	
	if($action == 'del')
	{
		$result = FALSE;
		if (isset($order_id))
			$result = DeleteOrder($order_id);
			
		if($result == FALSE)
			header("Location: /wks/order.php?error=1&e_action=del");	
		else
		{
			header("Location: /wks/order.php");	
		}
	}
?>